extends Camera

var ROT_SPEED = 1
var ZOOM_SPEED = 10

var MINIMUM_DISTANCE = 1

var INIT_PHI = 0.0
var INIT_THETA = 0.4
export var INIT_DISTANCE = 10

var point_at=Vector3()
var phi
var theta
var distance

#var target_phi = INIT_PHI

const FREQ=0.2

func _ready():
	reset_cam()

func _process(_delta):
	translation=point_at+distance*Vector3(
											sin(phi)*cos(theta), #x
											sin(theta), #y
											cos(phi)*cos(theta)) #z
	rotation=Vector3(-theta,phi,0)

func rot_horizontal(delta,right = true):
	phi=wrapf(phi+delta*ROT_SPEED*(1 if right else -1), 0, 2*PI)

func rot_vertical(delta,up = true):
	theta = clamp(theta+delta*ROT_SPEED*(1 if up else -1), -PI/2.0,PI/2.0)
	pass

func zoom(delta, away = true):
	distance += delta*ZOOM_SPEED*(1 if away else -1)

func reset_cam():
	point_at=Vector3(0,0,0)
	phi= INIT_PHI
	theta = INIT_THETA
	distance = INIT_DISTANCE
